/*
 * trunk/sbinfo.c
 *
 * Harry Wei <harryxiyou@gmail.com> 2012 (C)
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/kdev_t.h>

#define SB_LOCK_ADDRESS		(0xc177ce0c)
#define SUPER_BLOCKS_ADDRESS	(0xc1937aa0)

static int __init sbinfo_init(void) {
	struct super_block *sb = NULL;
	struct list_head *s_head = NULL;
	struct list_head *s_pos = NULL;
	struct list_head *i_pos = NULL;
	spinlock_t *spl = NULL;
	struct inode *inode = NULL;

	spl = (spinlock_t *) SB_LOCK_ADDRESS;
	s_head = (struct list_head *) SUPER_BLOCKS_ADDRESS;
	printk(KERN_DEBUG "sbinfo init ...\n");
	spin_lock(spl);
	list_for_each(s_pos, s_head) { //Macro for for easy use
		sb = list_entry(s_pos, struct super_block, s_list);
		printk(KERN_DEBUG "dev_num: %d:%d, count:%d, file_type:%s\n", 
						MAJOR(sb->s_dev), MINOR(sb->s_dev),
						sb->s_count, sb->s_type->name);
		list_for_each(i_pos, &sb->s_inodes) {
			inode = list_entry(i_pos, struct inode, i_sb_list);
			printk(KERN_DEBUG "inode number:%lx\n", inode->i_ino);
		}
	}
	spin_unlock(spl);
	return 0;
}

static void __exit sbinfo_exit(void) {
	printk(KERN_DEBUG "sbinfo exit ...\n");
	return ;
}

MODULE_LICENSE("GPL");
module_init(sbinfo_init);
module_exit(sbinfo_exit);
